package com.lu.springbootinit.bizmq;

import com.lu.springbootinit.constant.BiMQConstant;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class BiInitMain {
    public static void main(String[] args) {
        try {
            // 创建连接工厂
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            factory.setUsername("lu");
            factory.setPassword("Lqb326706");
            factory.setVirtualHost("/lel");
            // 创建连接
            Connection connection = factory.newConnection();
            // 创建通道
            Channel channel = connection.createChannel();
            String EXCHANGE_NAME = BiMQConstant.BI_EXCHANGE_NAME;
            channel.exchangeDeclare(EXCHANGE_NAME, "direct");
            // 创建队列，随机分配一个队列名称
            String queueName = BiMQConstant.BI_QUEUE_NAME;
            // 声明队列，设置队列持久化、非独占、非自动删除，并传入额外的参数为 null
            channel.queueDeclare(queueName, true, false, false, null);
            channel.queueBind(queueName, EXCHANGE_NAME, BiMQConstant.BI_ROUTING_KEY);
            BiMessageProducer biMessageProducer = new BiMessageProducer();
            biMessageProducer.sendMessage("nihao");
            System.out.println("发送");
        }catch (Exception e){

        }
    }
}
